# coding=utf-8

import redis
import time


class RedisDB(object):
    """
    notify-keyspace-events "Ex"
    """
    def __init__(self, db):
        self.pool = redis.ConnectionPool(host='localhost', port=6379, db=db)

    def getRedis(self):
        return redis.StrictRedis(connection_pool=self.pool)

    def getSubscribe(self, db):
        return '__keyevent@' + str(db) + '__:expired'


# _monkeyredisdb = RedisDB(0).getRedis()

if __name__ == '__main__':
    r = RedisDB(0).getRedis()
    # r.delete()
    # r.setex('a', 2, 12)
    # p = r.pubsub()
    # p.psubscribe('__keyevent@0__:expired')
    #
    # for i in p.listen():
    #     print i




